package com.imon.webbox.court.web;

import java.util.Collections;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.imon.webbox.court.domain.Reservation;
import com.imon.webbox.court.service.ReservationService;

@Controller
@RequestMapping("/reservationQuery")
public class ReservationQueryController {

	@Resource
	private ReservationService reservationService;

	@RequestMapping(method = RequestMethod.GET)
	public void setupForm() {

	}

	@RequestMapping(method = RequestMethod.POST)
	public String submitForm(@RequestParam("courtName") String courtName,
			Model model) {
		List<Reservation> reservations = Collections.emptyList();
		if (courtName != null) {
			reservations = reservationService.query(courtName);
		}

		model.addAttribute("reservations", reservations);
		return "reservationQuery";
	}
}
